package com.blazer.e;

public class test10 {
    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6,7,8};
        int index=binary(arr,60);
        System.out.println(index);
    }
    public static int binary(int[] arr,int data){
        int min=0;
        int max=arr.length-1;
        int mid=0;
        while (min<=max){
            mid=(min+max)/2;
            if(data>arr[mid]){
                min=mid+1;

            }else if(data<arr[mid]){
                max=mid-1;
            }else{
                return mid;
            }
        }
        return -1;
    }
}
